#coding=utf-8
"""
@author : leecrest
@time   : 14-3-1 下午7:51
@brief  : 修改单张png文件的尺寸，并转化成ico文件
"""

SIZE = (16, 32, 48, 248)

import Image
import os

FILE_EXT = ".png"
TMP_PATH = "./Tmp"

if not os.path.exists(TMP_PATH):
	os.mkdir(TMP_PATH)

for sFile in os.listdir("./"):
	if not os.path.isfile(sFile):
		continue
	sName, sExt = os.path.splitext(sFile)
	if sExt.lower() != FILE_EXT:
		continue
	cmd = "png2ico.exe %s.ico" % sName
	img = Image.open(sFile)
	for w in SIZE:
		new_img = img.resize((w, w), Image.ANTIALIAS) # w代表宽度，h代表高度，最后一个参数指 定采用的算法
		sNewFile = "%s/%s%dX%d%s" % (TMP_PATH, sName, w, w, FILE_EXT)
		new_img.save(sNewFile, quality=100)
		cmd += " %s" % sNewFile
	os.system(cmd)

cmd = "rd /s /q \"%s\"" % TMP_PATH
os.system(cmd)
